home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / tktoolbarbutton.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-05-30  |  6.4 KB  |  228 lines

  1. /*
  2.  * Kivio - Visual Modelling and Flowcharting
  3.  * Copyright (C) 2000 theKompany.com
  4.  *
  5.  * This program is free software; you can redistribute it and/or
  6.  * modify it under the terms of the GNU General Public License
  7.  * as published by the Free Software Foundation; either version 2
  8.  * of the License, or (at your option) any later version.
  9.  *
  10.  * This program is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  * GNU General Public License for more details.
  14.  *
  15.  * You should have received a copy of the GNU General Public License
  16.  * along with this program; if not, write to the Free Software
  17.  * Foundation, Inc., 51 Franklin Street, Fifth Floor,
  18.  * Boston, MA 02110-1301, USA.
  19.  */
  20. #ifndef TKTOOLBARBUTTON_H
  21. #define TKTOOLBARBUTTON_H
  22.  
  23. #include <tkaction.h>
  24.  
  25. #include <qpixmap.h>
  26. #include <qtoolbutton.h>
  27. #include <kglobal.h>
  28.  
  29. class KToolBar;
  30. class KInstance;
  31. class QPopupMenu;
  32. class QPainter;
  33.  
  34. class TKToolBarButton : public QToolButton
  35. { Q_OBJECT
  36. public:
  37.   TKToolBarButton(const QString& icon, const QString& txt,
  38.                      QWidget* parent = 0, const char *name=0L,
  39.                      KInstance *_instance = KGlobal::instance());
  40.  
  41.   TKToolBarButton(const QPixmap&, const QString&, QWidget* parent=0, const char* name=0);
  42.   ~TKToolBarButton();
  43.  
  44.   void setIconMode(TK::IconMode);
  45.   void setRaised(bool);
  46.   void setAutoRaised(bool);
  47.  
  48.   /**
  49.    * Enable/Disable this button
  50.    *
  51.    * @param enable Defaults to true
  52.    */
  53.   void setEnabled(bool enable = true);
  54.  
  55.   /**
  56.    * Set the pixmap directly for this button.  This pixmap should be
  57.    * the active one... the dimmed and disabled pixmaps are constructed
  58.    * based on this one.  However, don't use this function unless you
  59.    * are positive that you don't want to use @ref setIcon.
  60.    *
  61.    * @param pixmap The active pixmap
  62.    */
  63.   virtual void setPixmap(const QPixmap &pixmap);
  64.  
  65.   /**
  66.    * Set the pixmap directly for this button.  This pixmap should be
  67.    * the active one.. however, the disabled and default pixmaps will
  68.    * only be constructed if @ref #generate is true.  In any event,
  69.    * don't use this function unless you are positive that you don't
  70.    * want to use @ref setIcon.
  71.    *
  72.    * @param pixmap   The active pixmap
  73.    * @param generate If true, then the other pixmaps will be
  74.    *                 automatically generated using configurable effects
  75.    */
  76.   virtual void setPixmap(const QPixmap &pixmap, bool generate);
  77.  
  78.   /**
  79.    * Force the button to use this pixmap as the default one rather
  80.    * then generating it using effects.
  81.    *
  82.    * @param pixmap The pixmap to use as the default (normal) one
  83.    */
  84.   virtual void setDefaultPixmap(const QPixmap& pixmap);
  85.  
  86.   /**
  87.    * Force the button to use this pixmap when disabled one rather then
  88.    * generating it using effects.
  89.    *
  90.    * @param pixmap The pixmap to use when disabled
  91.    */
  92.   virtual void setDisabledPixmap(const QPixmap& pixmap);
  93.  
  94.   /**
  95.    * Set the text for this button.  The text will be either used as a
  96.    * tooltip (IconOnly) or will be along side the icon
  97.    *
  98.    * @param text The button (or tooltip) text
  99.    */
  100.   virtual void setText(const QString &text);
  101.   QString text();
  102.  
  103.   /**
  104.    * Set the icon for this button.  This icon should be the active
  105.    * one... the dimmed and disabled icons are constructed based on
  106.    * this one.  The actual pixmap will be loaded internally.  This
  107.    * function is preferred over @ref setPixmap
  108.    *
  109.    * @param icon The name of the active pixmap
  110.    */
  111.   virtual void setIcon(const QString &icon);
  112.  
  113.   /**
  114.    * Force the button to use this icon as the default one rather
  115.    * then generating it using effects.
  116.    *
  117.    * @param icon The icon to use as the default (normal) one
  118.    */
  119.   virtual void setDefaultIcon(const QString& icon);
  120.  
  121.   /**
  122.    * Force the button to use this icon when disabled one rather then
  123.    * generating it using effects.
  124.    *
  125.    * @param icon The icon to use when disabled
  126.    */
  127.   virtual void setDisabledIcon(const QString& icon);
  128.  
  129.   /**
  130.    * Turn this button on or off
  131.    *
  132.    * @param flag true or false
  133.    */
  134.   void on(bool flag = true);
  135.  
  136.   /**
  137.    * Toggle this button
  138.    */
  139.   void toggle();
  140.  
  141.   /**
  142.    * Turn this button into a toggle button or disable the toggle
  143.    * aspects of it.  This does not toggle the button itself.  Use @ref
  144.    * toggle for that.
  145.    *
  146.    * @param toggle true or false
  147.    */
  148.   void setToggle(bool toggle = true);
  149.  
  150.   /**
  151.    * Return a pointer to this button's popup menu (if it exists)
  152.    */
  153.   QPopupMenu *popup();
  154.  
  155.   /**
  156.    * Give this button a popup menu.  There will not be a delay when
  157.    * you press the button.  Use @ref setDelayedPopup if you want that
  158.    * behavior
  159.    *
  160.    * @param p The new popup menu
  161.    */
  162.   void setPopup (QPopupMenu *p);
  163.  
  164.   /**
  165.    * Gives this button a delayed popup menu.
  166.    *
  167.    * This function allows you to add a delayed popup menu to the button.
  168.    * The popup menu is then only displayed when the button is pressed and
  169.    * held down for about half a second.  You can also make the poup-menu
  170.    * "sticky", i.e. visible until a selection is made or the mouse is
  171.    * clikced elsewhere, by simply setting the second argument to true.
  172.    * This "sticky" button feature allows you to make a selection without
  173.    * having to press and hold down the mouse while making a selection.
  174.    *
  175.    * @param p the new popup menu
  176.    * @param toggle if true, makes the button "sticky" (toggled)
  177.    */
  178.   void setDelayedPopup(QPopupMenu *p, bool toggle = false);
  179.  
  180.   QPixmap getActivePixmap() const;
  181.  
  182.   virtual QSize sizeHint() const;
  183.   virtual QSize minimumSizeHint() const;
  184.  
  185. signals:
  186.   void buttonClicked();
  187.   void buttonPressed();
  188.   void buttonReleased();
  189.   void buttonToggled();
  190.  
  191. public slots:
  192.   void modeChange();
  193.  
  194. protected:
  195.   void paletteChange(const QPalette &);
  196.   void leaveEvent(QEvent *e);
  197.   void enterEvent(QEvent *e);
  198.   void drawButton(QPainter *p);
  199.   bool eventFilter (QObject *o, QEvent *e);
  200.   void showMenu();
  201.  
  202.   void makeDefaultPixmap();
  203.   void makeDisabledPixmap();
  204.   bool arrowPressed( const QPoint& pos ) {
  205.     int x = pos.x();
  206.     int y = pos.y();
  207.     return (x > width() - 12 && x <= width() && y > 0 && y < height());
  208.   }
  209.  
  210. private:
  211.   QPixmap defaultPixmap;
  212.   QPixmap activePixmap;
  213.   QPixmap disabledPixmap;
  214.   virtual void setIcon(const QPixmap &p) { QButton::setIcon(p); }
  215.   class TKToolBarButtonPrivate;
  216.   TKToolBarButtonPrivate *d;
  217.  
  218.  
  219. protected slots:
  220.   void slotClicked();
  221.   void slotPressed();
  222.   void slotReleased();
  223.   void slotToggled();
  224.   void slotDelayTimeout();
  225. };
  226.  
  227. #endif
  228.